package impl

import (
	pbcom "hundsun.com/hsl/hschain/protos/common"
	"hundsun.com/hsl/hschain/store/mq"
)

// AddSubscriber 注册订阅过滤器
func (chain *BlockChain) AddSubscriber(msg *mq.Message) {
	req := msg.Data.(*pbcom.ReqSubscriber)
	if req == nil {
		chain.log.Error("addSubscriber msg is nil")
		return
	}
	chain.pubsubMgr.AddSubscriber(req)
}

// DeleteSubscriber 取消注册订阅过滤器
func (chain *BlockChain) DeleteSubscriber(msg *mq.Message) {
	req := msg.Data.(*pbcom.ReqSubscriber)
	if req == nil {
		chain.log.Error("DeleteSubscriber msg is nil")
		return
	}
	chain.pubsubMgr.DelSubscriber(req)
}

// ProcWorkerHeartbeat prc worker hearbeat
func (chain *BlockChain) ProcWorkerHeartbeat(msg *mq.Message) {
	workerID, ok := msg.Data.(int)
	if ok {
		// 设置心跳
		chain.heartbeatMgr.Set(workerID, 0)
	}
}
